home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13689 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  77 lines

  1. Path: newsie.dmc.com!usenet
  2. From: prozac@cape.com
  3. Newsgroups: comp.lang.c
  4. Subject: Re: File problem with Watcom C/C++ 10.5
  5. Date: 9 Apr 1996 20:30:01 GMT
  6. Organization: Just Some Guy
  7. Distribution: world
  8. Message-ID: <4kehca$iar@newsie.dmc.com>
  9. References: <4k9fds$4fs@sparcserver.lrz-muenchen.de>
  10. NNTP-Posting-Host: tsa_65.cape.com
  11. Mime-Version: 1.0
  12. Content-Type: Text/Plain; charset=US-ASCII
  13. X-Newsreader: WinVN 0.99.6
  14.  
  15. >From: Ralph Reichart <reichart@informatik.tu-muenchen.de>
  16. >Newsgroups: comp.lang.c
  17. >Subject: File problem with Watcom C/C++ 10.5
  18. >
  19. >#include <stdlib.h>
  20. >#include <stdio.h>
  21. >
  22. >main()
  23. >{
  24. > FILE *Datei;
  25. >
  26. > Datei = fopen("\autoexec.bat", "r");
  27. > if (Datei == NULL)
  28. > {
  29. >  printf("\nSHIT!!");
  30. >  exit(1);
  31. > };
  32. > fclose(Datei);
  33. >}
  34. >
  35. >i'm sorry, but i can't open it. i always have the value -1 or 1 in errno.
  36. >yes, the file exists, but it doesn't matter. it never works.
  37. >can somebody please help me??
  38.  
  39. There is a more or less obvious error in the string literal
  40. that makes up the file name (look hard, you'll find it ;-).
  41.  
  42. Here's two good tips for getting your code to help you
  43. find out out why library functions (many of them anyway):
  44.  
  45.    Use the error reporting library functions.
  46.  
  47.    Use string pointers instead of literals for your
  48.       diagnostic messages.
  49.  
  50. Try this and IT WILL TELL YOU WHAT THE ERROR IS:
  51.  
  52. #include <stdlib.h>
  53. #include <stdio.h>
  54. #include <errno.h>
  55.  
  56. main()
  57. {
  58.  FILE *Datei;
  59.  char *File = "\autoexec.bat";
  60.  
  61.  errno = 0;
  62.  Datei = fopen(File, "r");
  63.  if (Datei == NULL)
  64.  {
  65.   printf("\nSHIT!!");
  66.   perror(File);
  67.   exit(1);
  68.  };
  69.  fclose(Datei);
  70. }
  71.  
  72. See what the error is now?
  73.  
  74. The standard library is YOUR FRIEND!
  75.  
  76.  
  77.